home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10940 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: ix.netcom.com!news
  2. From: bob_m@ix.netcom.com(Bob M )
  3. Newsgroups: comp.lang.c++
  4. Subject: References & Pointers in Borland C++
  5. Date: 11 Mar 1996 21:39:49 GMT
  6. Organization: Netcom
  7. Message-ID: <4i26j5$roe@dfw-ixnews3.ix.netcom.com>
  8. NNTP-Posting-Host: har-ct7-19.ix.netcom.com
  9. X-NETCOM-Date: Mon Mar 11  3:39:49 PM CST 1996
  10.  
  11. I am trying to understand the concept of "References".
  12.  
  13. But a couple of things are confusing me.
  14.  
  15. 1.
  16. The Programmer's manuals for Borland Turbo C++ version 1.01 (1990)
  17. and Borland C++ version 4.02 describe in nearly identical text, that
  18. it is acceptable to initialize a Reference with a specific number:
  19. int& ir = 6;
  20. Both my 3.1 and 4.02 compilers reject this with an error: "Reference 
  21. initialized with 'int' needs lvalue of type 'int'".
  22. Which is right, the compiler or the book?
  23.  
  24. 2.
  25. Using the Inspector window in the Debugger, I could see that a 
  26. Reference appears identical to a pointer, except that the compiler
  27. insists that you initialize it to some selected variable.
  28. It looks as though one should be able to assign a "filled in"
  29. pointer to a reference, as follows:
  30. int num, nother;
  31. int &ref1 = num, &ref2 = nother;
  32. int *ptr1;
  33.  
  34. ptr1 = &ref1;  // sets the pointer to the same address as "num".
  35. &ref2 = ptr1;  // Change &ref2 to point at "num".
  36.  
  37. The first assignment is apparently legal, but the second depends
  38. on the version of the compiler. 3.1 accepts it, while 4.01 says:
  39. "Lvalue required in function main".
  40. Should this be legal?
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.